package dxn.nl.file.biz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import dxn.nl.file.biz.ImportStatusEnum;
import dxn.nl.file.biz.dao.ExcelImportDao;
import dxn.nl.file.biz.po.FileExportApplyDetail;
import dxn.nl.file.biz.po.FileImportFileDetail;
import dxn.nl.file.biz.service.ImportFileBaseService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ImportFileBaseServiceImpl extends ServiceImpl<ExcelImportDao, FileImportFileDetail> implements ImportFileBaseService {
    @Override
    public int updateStatus(Long id, ImportStatusEnum statusEnum, int lastDealRow, String message) {
        FileImportFileDetail fileDetail = new FileImportFileDetail();
        fileDetail.setId(id);
        fileDetail.setStatusCode(statusEnum.code);
        fileDetail.setMessage(message);
        if(ImportStatusEnum.start_deal == statusEnum)
        {
            fileDetail.setStartTime(LocalDateTime.now());
        }
        if(ImportStatusEnum.fail == statusEnum || ImportStatusEnum.ok == statusEnum)
        {
            fileDetail.setEndTime(LocalDateTime.now());
        }

        LambdaQueryWrapper<FileImportFileDetail> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(FileImportFileDetail::getId, id);

        return this.baseMapper.update(fileDetail,lambdaQueryWrapper);
    }

    @Override
    public List<FileImportFileDetail> selectNeedDealRow(String tag) {
        List<FileImportFileDetail> list = this.baseMapper.selectConsumeList(tag);
        return list;
    }
}
